home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-08-20 | 10.0 KB | 365 lines | [TEXT/MPS ] |
- \ ***************************************************************
- \ * Sample FCode driver for a "display" card.
- \ *
- \ * Note that this version supports the Multi-color Terminal
- \ * Emulator extension, as implemented in the A7 (and, beyond) ROM.
- \ * The exact behavior of the Terminal Emulator may change.
- \ *
- \ * In particular, the new version will set FOREGROUND-COLOR
- \ * and BACKGROUND-COLOR to 0 and 15 if it detects our
- \ * "ISO6429-1983-COLORS" property. This version of the driver
- \ * initializes the CLUT based upon whether it detects the presence
- \ * of an implementation of FOREGROUND-COLOR. If not, it will
- \ * initialize so that the standard 1275 Terminal Emulator works.
- \ ***************************************************************
-
- \ ***************************************************************
- \ * NOTE: The following PCI-HEADER arguments are correct for this
- \ * card. They MUST correspond to your devices Device-ID, Vendor-ID
- \ * and CLASS-CODE.
- \ ***************************************************************
- tokenizer[ hex 100E 9001 030000 decimal ]tokenizer PCI-HEADER
-
- FCODE-VERSION2
-
- HEADERLESS
- 0 value MEM-SPACE-SIZE \ size of
- 0 value FRAME-BFR-PHYS \ frame buffer physical address
- 0 value VIPER# \ config #
- 0 value IO-SPACE-SIZE \ from 2nd config
- 0 value IO-SPACE-PHYS \ from "assigned addresses"instance
- 0 value IO-BASE \ for I/O cycle generationinstance
- 0 value REG-BASE \ for 9000 register accesses
- 0 value FRAME-BFR-VIRT \ frame buffer virtual address
-
- : >Command h# 04 + ;
- : >Base0 h# 10 + ;
- : >Base1 h# 14 + ;
- : config-b@ " config-b@" $call-parent ;
- : config-b! " config-b!" $call-parent ;
- : config-w@ " config-w@" $call-parent ;
- : config-w! " config-w!" $call-parent ;
- : config-l@ " config-l@" $call-parent ;
- : config-l! " config-l!" $call-parent ;
- : command-set VIPER# >Command tuck config-w@ or swap config-w! ;
- : command-clr invert VIPER# >Command tuck config-w@ and swap config-w! ;
- : io-b@ io-base + rb@ ;
- : io-b! io-base + rb! ;
- : io-w@ io-base + rw@ ;
- : io-w! io-base + rw! ;
- : reg-l@ reg-base + rl@ ;
- : reg-l! reg-base + rl! ;
- : map-in " map-in" $call-parent ;
- : map-out " map-out" $call-parent ;
- : ENCODE-PCI-REG
- >r >r VIPER# or encode-int rot encode-int encode+ rot encode-int encode+
- r> r> encode-int rot encode-int encode+ encode+
- ;
-
- hex
- \ following are offset to Memory addresses
- 004 constant kdSysConfig
- 008 constant kdInterrupt
- 00C constant kdInterruptEnable
- 104 constant kdHorzCounter
- 108 constant kdHorzLength
- 10C constant kdHorzSyncRisingEdge
- 110 constant kdHorzBlankRisingEdge
- 114 constant kdHorzBlankFallingEdge
- 118 constant kdHorzCounterPreload
- 11C constant kdVertCounter
- 120 constant kdVertLength
- 124 constant kdVertSyncRisingEdge
- 128 constant kdVertBlankRisingEdge
- 12C constant kdVertBlankFallingEdge
- 130 constant kdVertCounterPreload
- 134 constant kdScreenRepaintAddress
- 138 constant kdScreenRepaintTiming
- 13C constant kdScreenRefreshTiming
- 184 constant kdMemConfig
- 188 constant kdRefreshPeriod
- 190 constant kdRasMax
-
- \ following addresses are I/O addresses
- 8402 constant kBT485Reg0
- 8800 constant kBT485Reg1
- 8801 constant kBT485Reg2
- 8802 constant kBT485Reg3
- 03C6 constant kPixelMask
- 03C7 constant kRamRead
- 03C8 constant kRamWrite
- 03C9 constant kRamData
- decimal
-
- my-space to VIPER#
- -1 VIPER# >base0 config-l!
- VIPER# >base0 config-l@ h# FFFFFFF0 and negate to mem-space-size
- 0 VIPER# >base0 config-l!
- h# 10000 to io-space-size
- h# 8000 VIPER# >base1 config-l!
- " AAPL,Viper" device-name
- 0 0 0 0 0
- encode-pci-reg
- 0 0 h# 02000010 mem-space-size 0
- encode-pci-reg encode+
- 0 0 h# 81000000 io-space-size 0
- encode-pci-reg encode+
- " reg" property
- " display" device-type
- " viper" model
-
- 640 encode-int " width" property
- 480 encode-int " height" property
- 8 encode-int " depth" property
- 640 encode-int " linebytes" property
- 0 0 " iso6429-1983-colors" property \ we support extensions
-
- 0 value clkx
- : clk! ( data clk )
- 2 << swap 3 << or clkx or h# 3C2 io-b!
- ;
-
- : setupClock ( _vclk )
- h# 3CC io-b@ h# F3 and to clkx \ get "whatever"
-
- \ unlock the clock chip
- 1 1 clk!
- 5 0 do
- 1 0 clk!
- 1 1 clk!
- loop
- 1 0 clk!
- 0 0 clk!
- 0 1 clk!
-
- \ start bits
- 0 0 clk!
- 0 1 clk!
-
- \ Manchester encode the value
- 24 0 do ( vclk )
- dup 1 xor 1 and dup 1 clk! 0 clk! ( vclk )
- dup 1 and dup 0 clk! 1 clk! ( vclk )
- 1 >> ( vclk )
- loop
- drop ( -- )
-
- \ stop bits
- 1 1 clk!
- 1 0 clk!
- 1 1 clk!
- ;
-
- : setupDAC ( _vclk _depth )
- h# 82 kBT485Reg0 io-b!
- h# 30 kBT485Reg2 io-b!
- h# 01 kRamWrite io-b!
- over h# 20 and if h# 08 else h# 00 then kBT485Reg3 io-b! ( vclk depth )
- dup case ( vclk depth depth )
- 8 of
- h# 40
- endof
- 16 of
- h# 30
- endof
- 24 of
- h# 10
- endof
- 32 of
- h# 10
- endof
- endcase ( vclk depth val )
- kBT485Reg1 io-b! ( vclk depth )
- h# FF kPixelmask io-b! ( vclk depth )
- h# 12 h# 03C4 io-b! ( vclk depth )
- h# 03C5 io-b@ h# 10 or h# 03C5 io-b! ( vclk depth )
-
- swap 8 >> setupClock ( depth )
-
- h# 0C h# 03C2 io-b! ( depth )
- 8 = if ( -- )
- 0 kRamWrite io-b!
- h# 100 0 do \ initialize to smooth grey
- h# FF i -
- dup kRamData io-b! \ red
- dup kRamData io-b! \ green
- kRamData io-b! \ blue
- loop
- then
- ;
-
- : VIPERinit
- 0 to FRAME-BFR-PHYS
- " assigned-addresses" get-my-property abort" no assigned-addresses"
- begin \ search for my FRAME-BFR base
- dup while
- decode-phys h# FF and h# 10 = if \ this is for BASE0
- drop to FRAME-BFR-PHYS
- else
- 2drop
- then
- decode-int drop decode-int drop \ size values
- repeat
- 2drop \ drop final prop.adr prop.len pair
-
- FRAME-BFR-PHYS h# 100000 + 0 h# 02000000 VIPER# or
- h# 200 map-in to reg-base \ get addressability to my regs
-
- 0 0 h# 81000000 VIPER# or
- io-space-size map-in to io-base \ and, dumb old I/O space
-
- 3 command-set \ enable both RAM and I/O cycles
-
- h# 00000080 kdInterruptEnable reg-l!
- h# 00000186 kdRefreshPeriod reg-l!
- h# 000000FA kdRasMax reg-l!
-
- h# 45A8BCD0 8 setupDAC \ clock
-
- h# 00000002 kdMemConfig reg-l!
- h# 00563000 kdSysConfig reg-l!
- 23 kdHorzSyncRisingEdge reg-l!
- 33 kdHorzBlankRisingEdge reg-l!
- 193 kdHorzBlankFallingEdge reg-l!
- 199 kdHorzLength reg-l!
- 0 kdHorzCounterPreload reg-l!
-
- 1 kdVertSyncRisingEdge reg-l!
- 25 kdVertBlankRisingEdge reg-l!
- 505 kdVertBlankFallingEdge reg-l!
- 525 kdVertLength reg-l!
- 0 kdVertCounterPreload reg-l!
-
- h# 1E5 kdScreenRepaintTiming reg-l!
-
- reg-base h# 200 map-out \ don't need regs anymore
- io-base io-space-size map-out \ nor, I/O
- 1 command-clr \ disable I/O for shared environment
- FRAME-BFR-PHYS h# 00200000 + 0 h# 02000000 VIPER# or
- h# 00200000 map-in to FRAME-BFR-VIRT \ get addressability to frame buffer
- ;
-
- decimal
-
- variable RGB-temp \ used for COLOR! & COLOR@
- : map-in-io
- 0 0 h# 81000000 VIPER# or io-space-size map-in to io-base
- 1 command-set \ enable I/O accesses
- ;
- : map-out-io
- 1 command-clr \ disable I/O
- io-base io-space-size map-out
- ;
- : rect-setup ( adr|index x y w h -- w adr|index xy-adr h )
- >r >r 640 * + frame-buffer-adr + r> -rot r>
- ;
- EXTERNAL
-
- \ ******* the following are new routines added by the Terminal Emulator Extensions
- : SET-COLORS ( adr index #indices -- )
- map-in-io
- swap kRamWrite io-b! \ initialize index
- ( #indices ) 0 ?do ( adr )
- dup c@ kRamData io-b! 1+ ( adr ) \ R
- dup c@ kRamData io-b! 1+ ( adr ) \ G
- dup c@ kRamData io-b! 1+ ( adr ) \ B
- loop ( adr )
- drop
- map-out-io
- ;
- : GET-COLORS ( adr index #indices -- )
- map-in-io
- swap kRamRead io-b! \ initialize index
- ( #indices ) 0 ?do ( adr )
- kRamData io-b@ over c! 1+ ( adr ) \ R
- kRamData io-b@ over c! 1+ ( adr ) \ G
- kRamData io-b@ over c! 1+ ( adr ) \ B
- loop ( adr )
- drop
- map-out-io
- ;
- : COLOR! ( r g b index -- )
- >r RGB-temp 2+ tuck c! 1- tuck c! 1- c! \ setup our packed buffer
- RGB-temp r> 1 set-colors \ and, use our own code
- ;
- : COLOR@ ( index -- r g b )
- RGB-temp swap 1 get-colors \ fetch one set
- RGB-temp dup c@ swap 1+ dup c@ swap 1+ c@ \ split them out
- ;
-
- : DRAW-RECTANGLE ( adr x y w h -- )
- rect-setup ( w adr xy-adr h )
- ( h ) 0 ?do ( w adr xy-adr )
- 2dup 4 pick move
- 2 pick 640 d+
- loop
- 3drop
- ;
- : FILL-RECTANGLE ( index x y w h -- )
- rect-setup >r swap r> ( w index xy-adr h )
- ( h ) 0 ?do ( w index xy-adr )
- dup 3 pick 3 pick fill
- 640 +
- loop
- 3drop
- ;
- : READ-RECTANGLE ( adr x y w h -- )
- rect-setup >r swap r> ( w xy-adr adr h )
- ( h ) 0 ?do
- 2dup 4 pick move
- 640 3 pick d+
- loop
- 3drop
- ;
-
- \ ***************************************************************
- \ Note that MY-OPEN does not return the flag associated with
- \ the OPEN call. The shell code generated by Open Firmware for
- \ the IS-INSTALL word generates the result value.
- \ ***************************************************************
-
- : my-open
- VIPERinit
- \ **********************************************************************
- \ * Note: the CLUT setup is being done depending upon the presence of
- \ * the FOREGROUND-COLOR FCode (which is new for 16-Color Extension).
- \ **********************************************************************
-
- \ ** detect if Terminal Emulator can support 16-colors
- h# 168 get-token drop ['] ferror <> if
-
- \ *** 16-color is supported by Terminal Emulator, so setup CLUT
- \ black red green brown blue magenta cyan white
- " "(000000 AA0000 00AA00 AA5500 0000AA AA00AA 00AAAA AAAAAA)" drop
- 0 8 set-colors
- \ grey red green yellow blue magenta cyan white
- " "(AAAAAA FF0000 00FF00 FFFF00 0000FF FF00FF 00FFFF FFFFFF)" drop
- 8 8 set-colors
- 15 \ leave WHITE background fill for clear routine
-
- else \ ** 16-color support not present, setup for standard 1275
-
- 0 0 0 0 color! \ initialize BACKGROUND color
- -1 -1 -1 h# FF color! \ initialize FOREGROUND color
- 0 \ leave WHITE background for clear
-
- then
-
-
- ( background ) FRAME-BFR-VIRT h# 00200000 rot fill \ clear the buffer
-
- default-font set-font
- 640 480 100 40 fb8-install
- FRAME-BFR-VIRT to frame-buffer-adr
- ;
- ['] my-open is-install
-
- : my-close
- FRAME-BFR-VIRT h# 00200000 map-out
- ;
- ['] my-close is-remove
-
- FCODE-END
-
- PCI-END
-